﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE;
using DAL;

namespace BLL
{
    public class VertexWorker
    {
        private VertexDA dbInstance;

        public VertexWorker()
        {
            dbInstance = new VertexDA();
        }

        public Vertex GetVertex(int id)
        {
            return dbInstance.GetVertex(id);
        }

        public List<Vertex> GetAll()
        {
            return dbInstance.GetAllVertices();
        }

        public int Add(Vertex vertex, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Add;
            log.Event = "A location with following information has been added - Name: " + vertex.Name;

            lW.Add(log);

            return dbInstance.AddVertex(vertex);
        }

        public int Edit(Vertex vertex, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Edit;
            log.Event = "Location with ID = " + vertex.ID + " has been updated to following - Name: " + vertex.Name;

            lW.Add(log);

            return dbInstance.EditVertex(vertex);
        }

        public int Delete(Vertex vertex, string username)
        {
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Edit;
            log.Event = "Location with ID = " + vertex.ID + " and Name = " + vertex.Name + " has been deleted";

            lW.Add(log);

            return dbInstance.DeleteVertex(vertex.ID);
        }

		public SortedDictionary<int, Vertex> GetDictionariedVertices()
		{
			return dbInstance.GetDictionariedVertices();
		}
    }
}
